package thesis.filesharing.bo.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import thesis.filesharing.bo.DocumentFileBO;
import thesis.filesharing.common.exception.functional.InvalidArgumentException;
import thesis.filesharing.dao.DocumentFileDAO;
import thesis.filesharing.model.DocumentFile;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

@Service
public class DocumentFileBOImpl implements DocumentFileBO {
	
	@Autowired
	private DocumentFileDAO documentFileDAO;
	
	@Override
	public List<DocumentFile> saveDocumentFiles(List<DocumentFile> documentFiles, String[] classKeys) {
		if (classKeys.length <= 0) {
			throw new InvalidArgumentException();
		}
		List<Key> keys = new ArrayList<Key>();
		for (String k : classKeys) {
			keys.add(KeyFactory.stringToKey(k));
		}
		return documentFileDAO.saveDocumentFiles(documentFiles, keys);
	}

	@Override
	public List<DocumentFile> listDocumentFilesOfClass(Key classKey) {
		return documentFileDAO.listDocumentFilesOfClass(classKey);
	}

	@Override
	public DocumentFile findDocumentFile(Key documentFileKey) {
		return documentFileDAO.findDocumentFile(documentFileKey);
	}
}
